#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <colors>
#include <ncs_rpg_menu>

#include "ncs_rpg/variables.inc"
#include "ncs_rpg/logs.inc"
#include "ncs_rpg/helper.inc"
#include "ncs_rpg/api.inc"
#include "ncs_rpg/sql.inc"
#include "ncs_rpg/config.inc"
#include "ncs_rpg/events.inc"

public Plugin:myinfo =
{
	name		= "[New Classic Style] RPG",
	author		= "[RUS] DiviX",
	description	= "[New Classic Style] RPG",
	version		= VERSION,
	url			= "N/A"
};

public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
	RegPluginLibrary("ncs_rpg");
	
	// Natives
	CreateNative("RegisterSkill", 		Native_RegisterSkill);
	CreateNative("GetSkillCount", 		Native_GetSkillCount);
	CreateNative("GetSkillShortname",	Native_GetSkillShortname);
	CreateNative("GetSkillName",		Native_GetSkillName);
	CreateNative("GetSkillDesc",		Native_GetSkillDesc);
	CreateNative("GetSkillMaxLevel",	Native_GetSkillMaxLevel);
	CreateNative("GetSkillCost",		Native_GetSkillCost);
	
	CreateNative("IsValidPlayer", 		Native_IsValidPlayer);
	CreateNative("GetLevel", 			Native_GetLevel);
	CreateNative("GetXP",	 			Native_GetXP);
	CreateNative("GetReqXP",	 		Native_GetReqXP);
	CreateNative("GetCredits",	 		Native_GetCredits);
	CreateNative("GetSkillLevel", 		Native_GetSkillLevel);
	CreateNative("GetClientSkillCost",	Native_GetClientSkillCost);
	CreateNative("SetLevel", 			Native_SetLevel);
	CreateNative("SetXP",	 			Native_SetXP);
	CreateNative("SetCredits", 			Native_SetCredits);
	CreateNative("SetSkillLevel",		Native_SetSkillLevel);
	CreateNative("ResetPlayer",			Native_ResetPlayer);
	
	CreateNative("SetMaxHP",			Native_SetMaxHP);
	CreateNative("GetMaxHP",			Native_GetMaxHP);
	CreateNative("SetSpeed",			Native_SetSpeed);
	CreateNative("GetSpeed",			Native_GetSpeed);
	CreateNative("SetMaxSpeed",			Native_SetMaxSpeed);
	CreateNative("GetMaxSpeed",			Native_GetMaxSpeed);
	CreateNative("SetFreeze",			Native_SetFreeze);
	CreateNative("GetFreezeTime",		Native_GetFreezeTime);
	CreateNative("SetColor",			Native_SetColor);
	CreateNative("SetSlow",				Native_SetSlow);
	CreateNative("GetSlow",				Native_GetSlow);
	CreateNative("GetAlpha",			Native_GetAlpha);
	CreateNative("DealDamage",			Native_DealDamage);
	CreateNative("GetActiveWeapon",		Native_GetActiveWeapon);
	CreateNative("ShakePlayer",			Native_ShakePlayer);
	
	CreateNative("GetConfigValue",		Native_GetConfigValue);
	CreateNative("GetConfigValueFloat",	Native_GetConfigValueFloat);
	CreateNative("GetConfigValueString",Native_GetConfigValueString);
	
	// Forwards
	hFWD_OnDBConnected = CreateGlobalForward("RPG_OnDBConnected", ET_Ignore);
	hFWD_OnClientLoaded = CreateGlobalForward("RPG_OnClientLoaded", ET_Ignore, Param_Cell);
	hFWD_OnSkillsRegister = CreateGlobalForward("RPG_OnSkillsRegister", ET_Ignore);
	
	// Let plugin load.
	return APLRes_Success;
}

public OnPluginStart()
{
	LoadTranslations("ncs_rpg/ncs_rpg.skills.phrases");
	//LoadTranslations("ncs_rpg/ncs_rpg.xp.phrases");
	
	Logs();
	ConnectToDB();
	
	m_clrRender = FindSendPropOffs("CAI_BaseNPC","m_clrRender");
	
	HookEvents();
	
	LoadAllPlayers();
}

/* in sql.inc (connect)
public OnAllPluginsLoaded()
{
	OnSkillsRegister();
}*/

public OnPluginEnd()
{
	SaveAllPlayers();
}

public OnMapStart()
{
	LoadConfig();
	if(IsConnectedToDB())
		OnSkillsRegister();	
}

public OnClientConnected(client)
{
	ResetVariables(client);
}

public OnClientDisconnect(client)
{
	SavePlayer(client);
}